<template>
  <view>
    <view class="distinguish-btn" @click="handleClick">
      <view class="icon"></view>
      <view>{{ onOff ? "点击感应RFID标签" : "点击停止感应" }}</view>
    </view>

    <!-- <view v-for="(item, index) in list" :key="index">
      {{ index }}---{{ item.frequency }}
    </view> -->
  </view>
</template>
<script>
// 获取 module
var urovoRFIDModule = uni.requireNativePlugin("TH-PlatformRFID");

export default {
  data() {
    return {
      onOff: true,
      initRFIDStr: "",
      startInventoryStr: "",
      list: [],
    };
  },
  onLoad(options) {
    urovoRFIDModule.registerCallbackDatas((ret) => {
		  console.log(' registerCallbackDatas() ret == '+JSON.stringify(ret))
      this.list.push(ret);
    });
	
	this.initRFID();
  },
  methods: {
    handleClick() {
      if (this.onOff) {
		    console.log(' startInventory() ')
        this.list = [];
        this.startInventory();
        this.onOff = !this.onOff;
      } else {
		     console.log(' stopInventory() ')
        this.stopInventory();
        this.onOff = !this.onOff;
      }
    },
    initRFID() {
		 console.log(' initRFID() ' )
      urovoRFIDModule.initRFID('/dev/ttyHSL0"', "115200", (ret) => {
		   console.log(' initRFID() '+JSON.stringify(ret))
        this.initRFIDStr = JSON.stringify(ret);
		
      });
    },
    startInventory() {
		 console.log(' startInventory() ' )
      urovoRFIDModule.startInventory(0, 0, 0, 1, (ret) => {
        this.startInventoryStr = JSON.stringify(ret);
      });
    },
    stopInventory() {
      urovoRFIDModule.stopInventory();
    },
  },
};
</script>
<style >
.distinguish-btn {
  background: #3498ff;
  border-radius: 8px;
  font-size: 14px;
  color: #fff;
  text-align: center;
  padding: 27px 0 28px;
  margin-bottom: 10px;
}
.icon {
  width: 34px;
  height: 34px;
  margin: 0 auto;
  background-size: 34px 34px;
  margin-bottom: 5px;
}
</style>